package com.yhsimon.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class RestFulTest {

    //原来：http://localhost:8080/add?a=1&b=2
    @RequestMapping("/add")
    public String test1(int a, int b, Model model){
        int res=a+b;
        model.addAttribute("msg", "test01的结果为:"+res);
        return "test";
    }


    //RestFul风格
    @RequestMapping("/add/{a}/{b}")
    public String test2(@PathVariable int a,@PathVariable int b,Model model){
        int res=a+b;
        model.addAttribute("msg", "test02的结果为:"+res);
        return "test";
    }

    //method属性指定请求类型
    @RequestMapping(value = "/hello",method = RequestMethod.GET)
    public String test3(Model model){
        model.addAttribute("msg", "test3.....");
        return "test";
    }

    //test3等价于  @GetMapping
    @GetMapping("/hello/{a}/{b}")
    public String test4(@PathVariable int a,@PathVariable String b, Model model){
        String res=a+b;
        model.addAttribute("msg", res);
        return "test";
    }
}
